<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Angkatan extends MY_Controller {

    public function __construct() {
        parent::__construct();
        $this->load->model("angkatan_model", "am");
    }

    function index() {
        $perpage = 10;
        $curpage = $this->uri->segment(3);
        $data["txtSearch"] = $this->input->post("txtSearch");
        $like = "";
        if ($data["txtSearch"] != "")
            $like = array("angkatan_name" => $data["txtSearch"]);
        $data["alumni"] = $this->am->getAll($curpage, $perpage, @$where, @$like, "angkatan_year");
        $this->popuppaging(base_url()."angkatan/index", $this->am->getAllCount(@$where, @$like), $perpage);
        $this->myview(@$data, "angkatan/index");
    }
    
    function edit(){
        if ($this->sess->isadmin == 1) {
            if ($this->input->post()) {
                $data["alumni"]->angkatan_year = $this->input->post("txtYear");
                $data["alumni"]->angkatan_name = $this->input->post("txtName");
                
                $data["alumni"]->angkatan_name == "" ? $data["err"]->name = strErr("mustfilled") : "";
                
                if (@$data["err"]) {
                    $this->myview(@$data, "angkatan/edit", false, 1);
                } else {
                    $this->am->update($this->uri->segment(3), $data["alumni"]);
                    $this->session->set_flashdata("message", "Angkatan berhasil diubah");
                    $this->session->set_flashdata("redir", base_url() . "angkatan");
                    redirect(base_url() . "alert/success");
                }
            }else{
                $data["alumni"] = $this->am->getById($this->uri->segment(3));
                $this->myview(@$data, "angkatan/edit", false, 1);
            }
        } else {
            $this->session->set_flashdata("message", "Anda tidak mempunyai hak akses untuk halaman ini.");
            $this->session->set_flashdata("redir", base_url());
            redirect(base_url() . "alert/warning");
        }
    }
}
?>
